package common

// CmdOptions Transaction选项
type CmdOptions struct {
	Validators    map[string]Validator
	RequiredFlags []string
	HiddenFlags   []string
}

// CmdOption define single option function
type CmdOption func(*CmdOptions)

// WithRequiredFlag add required flag to option
func WithRequiredFlag(requiredFlags string) CmdOption {
	return func(o *CmdOptions) {
		o.RequiredFlags = append(o.RequiredFlags, requiredFlags)
	}
}

// WithHiddenFlag add hidden flag to option
func WithHiddenFlag(hiddenFlag string) CmdOption {
	return func(o *CmdOptions) {
		o.HiddenFlags = append(o.HiddenFlags, hiddenFlag)
	}
}

// WithCmdValidator add cmd validator to option
func WithCmdValidator(k string, vType ValidatorType) CmdOption {
	return func(o *CmdOptions) {
		if o.Validators == nil {
			o.Validators = make(map[string]Validator)
		}
		o.Validators[k] = NewValidator(vType)
	}
}

// GetCmdOption create CmdOption with given options
func GetCmdOption(opts []CmdOption) *CmdOptions {
	msgOpts := &CmdOptions{}
	for _, f := range opts {
		f(msgOpts)
	}
	return msgOpts
}
